<?php

class JifenModel extends DBModel
{
	protected $_table = '{{jifen}}';
	protected $_id = 'jid';
	
	public function getListByUserId($userid)
	{
		$where['from'] = '{{jifen}} j';
		$where['condition'] = 'j.userid = :userid';
		$where['select'] = 'j.jfcode jifenid,jg.hyhowmuch howmuch,j.createtime, jg.remark';
		$where['join'] = 'left join {{jifenguize}} jg on jg.jfcode = j.jfcode';
		$params[':userid'] = $userid;
		$where['order'] = 'j.createtime DESC';
		return $this->findAll($where, $params);
	}
	
	public function getRecord($userid)
	{
		$where['from'] = '{{jifen}} j';
		$where['condition'] = 'j.userid = :userid';
		$where['select'] = 'sum(jg.hyhowmuch)';
		$where['join'] = 'left join {{jifenguize}} jg on jg.jfcode = j.jfcode';
		$params[':userid'] = $userid;
		return $this->findScalar($where, $params);
	}
}